//
//  THHistoryViewController.m
//  Teacher-Help
//
//  Created by Taro on 15/11/5.
//  Copyright © 2015年 Taro. All rights reserved.
//

#import "THHistoryViewController.h"
#import "THDetailOfHistoryViewController.h"
#import "THClass.h"

@interface THHistoryViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic , strong) UITableView *tableView ;
@property (nonatomic , strong) NSMutableArray * classArray;
@property (nonatomic , strong) NSMutableArray * courseId;

@end

@implementation THHistoryViewController



- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.tableView = [[UITableView alloc] init];
    self.tableView.frame = self.view.frame;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
//    THLog(@"%@",_weekModel);
//    THLog(@"history%@",_cookie);
    [self.view addSubview:self.tableView];
    _classArray = [NSMutableArray array];
    _courseId = [NSMutableArray array];
    NSMutableArray *array = [NSMutableArray array];
    
    for (int i = 0; i < 7; i++) {
        NSArray *Ary = _weekModel[i];
        if (Ary.count != 0) {
            for (int a = 0; a < Ary.count; a++) {
                [array addObject:[_weekModel[i] objectAtIndex:a]];
            }
            
        }
    }
//    THLog(@"%@",array);
    for (int i = 0; i < array.count; i++) {
        THClass *class = array[i];
        [_classArray addObject:class.courseName];
        [_courseId addObject:class.courseId];
    }
//    THLog(@"%@",_classArray);
   
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _classArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *ID = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
    }
    cell.textLabel.text = _classArray[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    THDetailOfHistoryViewController *detail = [[THDetailOfHistoryViewController alloc] init];
    detail.courseId = _courseId[indexPath.row];
    detail.cookie = _cookie;
    [self.navigationController pushViewController:detail animated:YES];
}

@end
